<template>
	<view class="page" :style="themeColor">
		<view class="flex benben-position-layout flex flex-wrap align-center find_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub find_fd0_0'>
				<view class='flex flex-wrap align-center find_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
					data-url="1">
				</view>
				<view class='flex flex-wrap align-stretch justify-center flex-sub'>
					<text class='find_fd0_0_c1_c0'>发现</text>
				</view>
				<view class='flex flex-wrap align-center justify-end find_fd0_0_c0' @tap.stop="handleJumpDiy"
					data-type="navigateTo" :data-url="`/pages/faxian/releaseTrend/releaseTrend`">
					<image class='find_fd0_0_c2_c0' mode="aspectFit" :src='STATIC_URL+"23.png"'></image>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}">
			<web-view v-show="webView" :webview-styles="webviewStyles" :fullscreen="false" src="/hybrid/html/1.html" @message="onPostMessage"></web-view>
		</view>
		<!---flex布局flex布局开始-->
		<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout find_flex_1">
			<view class='flex flex-wrap align-center'>
				<view>
					<benben-flex-tabs class-name='find_benbenTabsfd1_0_c0' v-model="tabs" ref="benben_tabsfd1_0_c0"
						select-mark="benben_tabsfd1_0_c0" key="benben_tabsfd1_0_c0" :open-title-type='false'
						:open-sticky='true' :top='0' :is-show-content='false' :scrollspy='false'
						:tabs-info.sync="tabsInfofd1_0_c0" @change="tabsChange">

						<scroll-view @scroll="tabsInfofd1_0_c0.scrollX = $event.detail.scrollLeft"
							id="benben_tabsfd1_0_c0" class="benben-tabs" style="width:750rpx" :scroll-x="true"
							:scroll-left.sync="tabsInfofd1_0_c0.moveX" scroll-with-animation="all .3s ease">
							<view class="benben-tabs-content" id="benben_tabsfd1_0_c0-content">
								<view id="benben_tabsfd1_0_c0-title"
									class="benben-tabs-title flex flex align-center justify-around">
									<view
										:class="{ 'checkTitlefd1_0_c0': tabs == '1', 'flex flex-wrap align-center find_titlefd1_0_c0_c3': true }"
										@tap="tabs = '1'" :id="`benben_tabsfd1_0_c0-title-item-${'1'}`">

										<text>推荐</text>

									</view>
									<view
										:class="{ 'checkTitlefd1_0_c0': tabs == '2', 'flex flex-wrap align-center find_titlefd1_0_c0_c4': true }"
										@tap="tabs = '2'" :id="`benben_tabsfd1_0_c0-title-item-${'2'}`">

										<text>关注</text>

									</view>
								</view>
								<view :style="{ left: tabsInfofd1_0_c0.lineleft, maxWidth: tabsInfofd1_0_c0.lineWidth }"
									id="benben_tabsfd1_0_c0-line"
									class="benben-tabs-line flex benben-flex-tabs-line find_linefd1_0_c0">
								</view>
							</view>
						</scroll-view>

					</benben-flex-tabs>

				</view>
			</view>
		</view>
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#6A0002"></u-loading>
			<view class="loading_text">加载中</view>
		</view>

		<!---flex布局flex布局结束-->
		<!---flex布局flex布局开始-->
		<view class="flex benben-flex-layout flex-wrap align-center find_flex_2" v-else>
			<view class='flex flex-wrap align-center justify-between flex-sub find_fd2_0'>
				<block v-for="(v, k) in list" :key="k">
					<activity :item="v"></activity>
				</block>
			</view>
			<u-loadmore v-if="last_page > 1" class="loadmore" font-size="24" :status="status" :icon-type="iconType"
				:load-text="loadText" />
			<view class="noData_other" v-if="list.length == 0 && !isShow">
				<image src="/static/empty/no.png"></image>
				<view>没有动态~</view>
			</view>
		</view>

		<!---flex布局flex布局结束-->


	</view>
</template>
<script>
	import activity from '@/components/activity/index.vue'
	export default {
		components: {
			activity
		},


		data() {
			return {
				"tabsInfofd1_0_c0": {
					lineleft: '',
					lineWidth: '',
					moveX: 0,
					scrollX: 0,
					PageScrollX: 0
				},
				"tabs": "1",
				"lotusAddressData": {
					visible: false,
					provinceName: '',
					cityName: '',
					townName: '',
				}, // 选择的地址
				"list": [],
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"iconType": 'flower',
				"loadText": {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				"isShow": true,
				webviewStyles: {
					width: '1px',
					height: '1px',
					
				},
				webView: false,
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {

		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			if (uni.getStorageSync('lotusAddressData')) {
				this.lotusAddressData = uni.getStorageSync('lotusAddressData');
			}
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getActivityList();
		},
		onHide() {

		},
		onResize() {

		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getActivityList();
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {

				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				this.getActivityList();
			}, 500)
		},
		onPageScroll(e) {

		},
		methods: {
			// 根据ip获取地区
			onPostMessage(e) {
				// console.log(e.detail.data[0].code);
				uni.setStorageSync('ipCode', e.detail.data[0].code);
			},
			tabsChange(e) {
				this.page = 1;
				this.is_pull = true;
				this.isShow = true;
				this.getActivityList();
			},
			// 发现列表
			getActivityList() {
				this.$api.post(global.API_VERSION + '/647321f211044', {
					page: this.page,
					type: this.tabs,
					country: this.lotusAddressData.provinceName,
					city: this.lotusAddressData.cityName,
					area: this.lotusAddressData.townName
				}).then(res => {
					// console.log(res);
					uni.stopPullDownRefresh();
					this.isShow = false;
					if (res.data.code == 1) {
						this.last_page = res.data.data.last_page;
						if (this.is_pull) {
							this.list = res.data.data.data;
						} else {
							this.list = this.list.concat(res.data.data.data);
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			
			
			listenMusic(musicUrl, k) {
				console.log(musicUrl)
				this.closeVideo();
				if (k == 2) {
					this.analyze_listen = true
					this.listen = false
					this.questionData[this.optionIndex].option.forEach((v, k) => {
						v.is_music = false
					})
					innerAudioContext.src = musicUrl
					innerAudioContext.volume = 1
					innerAudioContext.play()
					innerAudioContext.onError((res) => {
						console.log(res)
						if(res) {
							this.$message.info('播放失败，请稍后再试')
						}
						this.analyze_listen = false
						return
					})
					this.$forceUpdate()
					innerAudioContext.onEnded((res) => {
						this.questionData[this.optionIndex].option[k].is_music = false
						this.$forceUpdate()
					})
					return
				}
				if (k != undefined) {
					this.analyze_listen = false
					this.listen = false
					this.questionData[this.optionIndex].option.forEach((v, k) => {
						v.is_music = false
					})
					this.questionData[this.optionIndex].option[k].is_music = true
					innerAudioContext.src = musicUrl
					innerAudioContext.volume = 1
					innerAudioContext.play()
					innerAudioContext.onError((res) => {
						console.log(res)
						if(res) {
							this.$message.info('播放失败，请稍后再试')
						}
						this.questionData[this.optionIndex].option[k].is_music = false
						return
					})
					this.$forceUpdate()
					innerAudioContext.onEnded((res) => {
						this.questionData[this.optionIndex].option[k].is_music = false
						this.$forceUpdate()
					})
				} else {
					this.questionData[this.optionIndex].option.forEach((v, k) => {
						v.is_music = false
					})
					innerAudioContext.src = musicUrl
					innerAudioContext.volume = 1
					innerAudioContext.play()
					innerAudioContext.onError((res) => {
						console.log(res)
						if(res) {
							this.$message.info('播放失败，请稍后再试')
						}
						this.listen = false
						return
					})
					this.listen = true
					this.analyze_listen = false
				}	
			},
			// 题目暂停
			listenMusic2(audio, id) {
				if (id == undefined) {
					if (this.listen) {
						innerAudioContext.pause()
						this.listen = false
					} else {
						innerAudioContext.play()
						this.listen = true
					}
				} else {
					if (this.analyze_listen) {
						innerAudioContext.pause()
						this.analyze_listen = false
					} else {
						innerAudioContext.play()
						this.analyze_listen = true
					}
				}
				
				innerAudioContext.onEnded((res) => {
					this.listen = false
					this.analyze_listen = false
				})
			},
			// 选项暂停
			listenMusic3(musicUrl, k) {
				// if ()
				if (this.questionData[this.optionIndex].option[k].is_music) {
					innerAudioContext.pause()
					this.questionData[this.optionIndex].option[k].is_music = false
					this.$forceUpdate()
				} else {
					innerAudioContext.play()
					this.questionData[this.optionIndex].option[k].is_music = true
					this.$forceUpdate()
				}
			},
			// 组合题 题目和选项播放
			listenMusic4(type, musicUrl, k, i) {
				this.closeVideo();
				if (type == 1) {
					this.analyze_listen = false
					this.listen = false
					this.questionData[this.optionIndex].item.forEach((v, k) => {
						v.is_music = false
					})
					this.questionData[this.optionIndex].item[k].is_music = true
					innerAudioContext.stop()
					innerAudioContext.src = musicUrl
					innerAudioContext.volume = 1
					innerAudioContext.play()
					innerAudioContext.onError((res) => {
						console.log(res)
						if (res) {
							this.$message.info('播放失败，请稍后再试')
						}
						this.questionData[this.optionIndex].item[k].is_music = false
						return
					})
					this.$forceUpdate()
					innerAudioContext.onEnded((res) => {
						this.questionData[this.optionIndex].item[k].is_music = false
						this.$forceUpdate()
					})
					
				} else {
					this.analyze_listen = false
					this.listen = false
					this.questionData[this.optionIndex].item.forEach((v, k) => {
						v.is_music = false
						v.option.forEach((v1, k1) => {
							v1.is_music = false
						})
					})
					this.questionData[this.optionIndex].item[k].option[i].is_music = true
					innerAudioContext.stop()
					innerAudioContext.src = musicUrl
					innerAudioContext.volume = 1
					innerAudioContext.play()
					innerAudioContext.onError((res) => {
						console.log(res)
						if (res) {
							this.$message.info('播放失败，请稍后再试')
						}
						this.questionData[this.optionIndex].item[k].option[i].is_music = false
						return
					})
					this.$forceUpdate()
					innerAudioContext.onEnded((res) => {
						this.questionData[this.optionIndex].item[k].option[i].is_music = false
						this.$forceUpdate()
					})
				}
				this.item = this.questionData[this.optionIndex];
				this.$set(this.item, this.questionData, this.optionIndex);
				this.$refs.practice.getItem();
			},
			// 组合题 题目和选项暂停
			listenMusic5(type, musicUrl, k, i) {
				if (type == 1) {
					if (this.questionData[this.optionIndex].item[k].is_music) {
						innerAudioContext.pause()
						this.questionData[this.optionIndex].item[k].is_music = false
					} else {
						innerAudioContext.play()
						this.questionData[this.optionIndex].item[k].is_music = true
					}
				} else {
					if (this.questionData[this.optionIndex].item[k].option[i].is_music) {
						innerAudioContext.pause()
						this.questionData[this.optionIndex].item[k].option[i].is_music = false
					} else {
						innerAudioContext.play()
						this.questionData[this.optionIndex].item[k].option[i].is_music = true
					}
				}
				this.item = this.questionData[this.optionIndex];
				this.$set(this.item, this.questionData, this.optionIndex);
				this.$refs.practice.getItem();
			},
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(248, 248, 248, 1);
		background-size: 100% auto !important;
	}

	.find_flex_0 {
		background: rgba(248, 248, 248, 1);
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.find_fd0_0_c2_c0 {
		width: 32rpx;
		height: 32rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.find_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}


	.find_fd0_0_c0 {
		width: 100rpx;
	}

	.find_fd0_0 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.find_flex_1 {
		background: var(--benbenbgColor0);
		margin: 0rpx 0rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		border-radius: 32rpx 32rpx 0rpx 0rpx;
		overflow: hidden;
	}

	.find_titlefd1_0_c0_c4 {
		margin: 0rpx 80rpx 0rpx 0rpx;
	}

	.find_titlefd1_0_c0_c3 {
		margin: 0rpx 0rpx 0rpx 80rpx;
	}

	.find_linefd1_0_c0 {
		// background: rgba(106, 0, 2, 1);
		background: url(/static/images/20.png) no-repeat;
		width: 24rpx;
		height: 20rpx;
		top: 78rpx;
		background-size: 100% auto !important;
	}

	.checkTitlefd1_0_c0 {
		font-weight: 500 !important;
		font-size: 32rpx !important;
		color: rgba(51, 51, 51, 1) !important;
	}

	::v-deep .find_benbenTabsfd1_0_c0 {
		background: rgba(248, 248, 248, 1);
		height: 90rpx;
		white-space: nowrap;
		text-align: center;
		font-style: normal;
		color: rgba(153, 153, 153, 1);
		font-size: 32rpx;
		font-weight: 400;
	}

	.find_flex_2 {
		margin: 40rpx 0rpx 0rpx 0rpx;
	}

	.find_fd2_0_c0_c5 {
		background: #333333;
		position: absolute;
		bottom: 164rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		width: 102rpx;
		height: 32rpx;
		padding: 0rpx 16rpx 0rpx 16rpx;
		right: 16rpx;
	}

	.find_fd2_0_c0_c4_c1 {
		color: var(--benbenFontColor3);
		font-size: 24rpx;
		font-weight: 400;
	}

	.find_fd2_0_c0_c4_c0 {
		width: 24rpx;
		height: 24rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.find_fd2_0_c0_c4 {
		background: #333333;
		position: absolute;
		bottom: 164rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		width: 102rpx;
		height: 32rpx;
		padding: 0rpx 16rpx 0rpx 16rpx;
		left: 16rpx;
	}

	.find_fd2_0_c0_c3 {
		width: 48rpx;
		height: 48rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		position: absolute;
		right: 150rpx;
		top: 150rpx;
	}

	.find_fd2_0_c0_c2_c2 {
		color: #BFBFBF;
		font-size: 20rpx;
		font-weight: 400;
		line-height: 30rpx;
		margin: 0rpx 0rpx 0rpx auto;
	}

	.find_fd2_0_c0_c2_c1 {
		color: #C4C4C4;
		font-size: 22rpx;
		font-weight: 400;
		line-height: 30rpx;
		margin: 0rpx 0rpx 0rpx 8rpx;
	}

	.find_fd2_0_c0_c2_c0 {
		width: 40rpx;
		height: 40rpx;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
	}

	.find_fd2_0_c0_c2 {
		margin: 0rpx 16rpx 32rpx 16rpx;
	}

	.find_fd2_0_c0_c1 {
		margin: 16rpx 16rpx 24rpx 16rpx;
		color: var(--benbenFontColor0);
		font-size: 26rpx;
		font-weight: 500;
		line-height: 37rpx;
	}

	.find_fd2_0_c0_c0 {
		width: 344rpx;
		height: 342rpx;
		border-radius: 16rpx 16rpx 0rpx 0rpx;
	}

	.find_fd2_0_c0 {
		background: var(--benbenbgColor0);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		box-shadow: 0rpx 6rpx 25rpx rgba(0, 0, 0, 0.1);
		margin: 0rpx 0rpx 24rpx 0rpx;
		position: relative;
	}

	.find_fd2_0 {
		margin: 0rpx 24rpx 0rpx 24rpx;
	}
</style>